package cn.tedu.api;

import java.math.BigDecimal;
import java.util.Scanner;

/**本类用于浮点数运算不精确的解决案例*/
public class TestBigDecimal2 {
    public static void main(String[] args) {
        f1();
    }

    private static void f1() {
        System.out.println("请您输入您要计算的数据");
        Scanner scanner = new Scanner(System.in);
        double a = scanner.nextDouble();
        double b = scanner.nextDouble();
        BigDecimal bd1 = new BigDecimal(a+"");
        BigDecimal bd2 = new BigDecimal(b+"");
        BigDecimal bd3;
        bd3 = bd1.add(bd2);
        System.out.println("加法运算结果为:"+bd3);
        bd3 = bd1.subtract(bd2);
        System.out.println("减法运算结果为:"+bd3);
        bd3 = bd1.multiply(bd2);
        System.out.println("乘法运算结果为:"+bd3);
        bd3 = bd1.divide(bd2,5,BigDecimal.ROUND_HALF_UP);
        System.out.println("除法运算结果为:"+bd3);
    }
}
